View Javadoc
1 /* 2 * Title: S/MIME Project 3 * Description: S/MIME email transport capabilities. 4 * @Author Vladan Obradovic 5 * @Version 2.0.1 6 */ 7 8 package org.webdocwf.util.smime.test; 9 10 11 import javax.mail.Transport; 12 import org.webdocwf.util.smime.smime.EnvelopedSMIME; 13 import org.webdocwf.util.smime.exception.SMIMEException; 14 15 16 /*** 17 * Tests enveloping process. Encrypted text/plain message with or 18 * withouth attachments can be sent by this test. To get help for this 19 * example type: "java org.webdocwf.util.smime.test.TestEncrypt" in command line. 20 * It is assumed that smime200tests.jar is in your classpath.<BR> 21 * <BR> 22 * Parameters passed to example are:<BR> 23 * <mailHost> <mailAddress> <cerFileName> <algorithmName> 24 * [<attachment>]<BR> 25 * <BR> 26 * <algorithmName> could be: RC240, RC264, RC2128, 3DES or 3DES<BR> 27 * <BR> 28 * Note that for this example email address "FROM" is fixed to: "sender@seateam.co.yu". 29 * You should change this values in source code of TestEncrypt.java in order to use 30 * them with other "FROM" address. 31 */ 32 public class TestEncrypt { 33 34 public static void main(String[] args) { 35 36 String subject = "S/MIME encrypted message - Subject test: ÜüÄäÖöÜüß"; 37 String content = "S/MIME encrypted message example\r\nContent test: ÜüÄäÖöÜüß!"; 38 String from = "sender@seateam.co.yu"; 39 40 if (args.length < 4) { 41 System.err.println( 42 System.getProperty("line.separator") + 43 "Usage of TestEncrypt: " + 44 System.getProperty("line.separator") + 45 "java TestEncrypt <mailHost> <mailAddress> <cerFileName> " + 46 "<algorithmName> [<attachment>]" + 47 System.getProperty("line.separator") + 48 System.getProperty("line.separator") + 49 "Examples:" + 50 System.getProperty("line.separator") + 51 "java TestEncrypt seateam.co.yu recipient@seateam.co.yu " + 52 "recipient512.cer RC240 " + 53 System.getProperty("line.separator") + 54 "java TestEncrypt seateam.co.yu recipient@seateam.co.yu " + 55 "recipient512.cer DES .//test//Zip8Test.zip"); 56 System.exit(-1); 57 } 58 String smtpHost = args[0]; 59 String addressTO = args[1]; 60 String cerFileName = args[2]; 61 String algorithmName = args[3]; 62 String fileName = null; 63 64 if (args.length > 4) 65 fileName = args[4]; 66 67 String addressCC = "recipient@seateam.co.yu"; 68 String addressBCC = "recipient@seateam.co.yu"; 69 70 subject = algorithmName + " " + cerFileName + " " + subject; 71 72 EnvelopedSMIME es = null; 73 74 try { 75 es = new EnvelopedSMIME(smtpHost, from, subject, content); 76 77 if (fileName != null) { 78 es.addAttachment(fileName); // optional - use this if send attachment 79 } 80 81 es.setReply(from); // optional 82 83 es.addRecipient(addressTO, "TO", cerFileName); // mandatory 84 // es.addRecipient(addressCC, "CC", cerFileName); // optional 85 // es.addRecipient(addressBCC, "BCC", cerFileName); // optional 86 87 if (algorithmName.equals("RC240")) { 88 System.out.println("Creating the encrypted message with RC2_CBC - 40 bits algorithm... "); 89 es.enveloping(); // instead of this next line could be used 90 // es.enveloping("RC2_CBC", 40); 91 } else if (algorithmName.equals("RC264")) { 92 System.out.println("Creating the encrypted message with RC2_CBC - 64 bits algorithm... "); 93 es.enveloping("RC2_CBC", 64); // send message with RC2 - 64 bits algorithm 94 } else if (algorithmName.equals("RC2128")) { 95 System.out.println("Creating the encrypted message with RC2_CBC - 128 bits algorithm... "); 96 es.enveloping("RC2_CBC", 128); // send message with RC2 - 128 bits algorithm 97 } else if (algorithmName.equals("DES")) { 98 System.out.println("Creating the encrypted message with DES algorithm... "); 99 es.enveloping("DES", 56); // send message with DES algorithm 100 } else if (algorithmName.equals("3DES")) { 101 System.out.println("Creating the encrypted message with DES_EDE3_CBC algorithm... "); 102 es.enveloping("DES_EDE3_CBC", 192); // send message with 3DES algorithm 103 } 104 System.out.print("Sending encrypted message ... "); 105 es.send(); // instead of this next line could be used 106 // Transport.send(es.getSignedMessage()); 107 System.out.println("done."); 108 109 } catch (Exception e) { 110 SMIMEException.setErrorFilePath("Log"); //specifies directory for logging 111 if (e instanceof SMIMEException) { 112 // ((SMIMEException)e).loggingErrors(null); //logging 113 ((SMIMEException) e).displayErrors(null); 114 } else 115 System.out.println(e.getMessage()); 116 } 117 } 118 119 } 120

This page was automatically generated by Maven